<template>
  <el-drawer
    class="drawer-order-detail"
    :title="title"
    :visible.sync="show"
    direction="rtl"
    :size="size"
    :wrapperClosable="false"
    @close="close"
    append-to-body>
    <div class="drawer-content-item">
      <el-form ref="form" label-position="top" :model="form" label-width="0">
        <div class="flex-between-center content-padding">
          <el-row class="flex-1">
            <el-col :span="24">
              <el-form-item label="">
                <div class="fw-b font-s-20">
                  {{ form.orderNo }} - {{ form.name }}
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <div>
                <i class="userinfo-icon el-icon-mobile-phone"></i>
                <span>{{ form.phone || "-" }}</span>
              </div>
            </el-col>
            <el-col :span="7">
              <div>
                <i class="userinfo-icon el-icon-postcard"></i>
                <span>{{ form.idCard || "-" }}</span>
              </div>
            </el-col>
            <el-col :span="3">
              <div>
                <i class="userinfo-icon el-icon-user"></i>
                <span>{{ form.userInfo?form.userInfo.ethnicity:"-" }}</span>
              </div>
            </el-col>
            <el-col :span="3">
              <div>
                <i
                  v-if="form.sexCode == 1"
                  class="userinfo-icon el-icon-female"
                ></i>
                <i v-else class="userinfo-icon el-icon-male"></i>
                <span>{{ form.sexCode == 1 ? "女" : "男" }}</span>
              </div>
            </el-col>
          </el-row>
          <!-- <div class="order-right-btn">
            <el-button-group>
              <el-button
                size="mini"
                v-if="form.signMaterial"
                @click="windowOpen(form.signMaterial)"
                >借款协议</el-button
              >
              <el-button
                size="mini"
                v-if="form.creditMaterial"
                @click="windowOpen(form.creditMaterial)"
                >征信授权书</el-button
              >
            </el-button-group>
          </div> -->
        </div>
      </el-form>
    </div>
    <!-- <div class="drawer-content-item">
      <div class="order-progress-box">
        <div
          v-if="form.approveStatus != 13 || index < form.bigApproveStatus"
          :class="{ active: index < form.bigApproveStatus }"
          v-for="(item, index) in progressStatus"
          :key="index"
        >
          {{ item.label }}
        </div>
        <div v-if="form.orderStatus === 26" class="active">取消</div>
      </div>
    </div> -->
    <div class="drawer-content-item">
      <el-tabs v-model="tabsCurrent" type="card">
        <el-tab-pane label="申请信息" name="1">
          <el-form label-position="top">
            <div class="item-title-box">申请信息</div>
            <el-row :gutter="20" class="form-detail-top-box">
              <el-col :span="6">
                <el-form-item label="申请金额">
                  {{ form.applyAmount }} 元
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="借款期限">
                  {{
                    selectDictLabel(
                      dict.type.loan_days,
                      form.applyTotalDay
                    ) || "-"
                  }}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="还款周期">
                  {{
                    selectDictLabel(
                      dict.type.repayment_term,
                      form.applyTotalTerm
                    ) || "-"
                  }}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="还款方式">
                  {{
                    selectDictLabel(
                      dict.type.repayment_method,
                      form.repayMethod
                    ) || "-"
                  }}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="借款用途">
                  {{
                    selectDictLabel(
                      dict.type.loan_purpose,
                      form.loanPurpose
                    ) || "-"
                  }}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="申请时间">
                  {{ form.applyTime }}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="渠道来源">
                  {{ form.productName || "-" }}
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <template v-if="form.userInfo || form.userInfoExpand">
            <el-form label-position="top">
              <div class="item-title-box">个人资料</div>
              <el-row :gutter="20" class="form-detail-top-box">
                <template v-if="form.userInfo">
                  <el-col :span="6">
                    <el-form-item
                      label="身份证人像面"
                      prop="idCardBackPhoto"
                      class="mar-b-5"
                    >
                      <imagePreview :url="form.userInfo.idCardBackPhoto" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item
                      label="身份证国徽面"
                      prop="idCardFrontPhoto"
                      class="mar-b-5"
                    >
                      <imagePreview :url="form.userInfo.idCardFrontPhoto" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="真实姓名">
                      {{ form.userInfo.name || "-" }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="身份证号">
                      {{ form.userInfo.idCard || "-" }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="身份证地址">
                      {{ form.userInfo.idCardAddress || "-" }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="教育程度">
                      {{
                        selectDictLabel(
                          dict.type.education_level,
                          form.userInfoExpand.educationLevel
                        ) || "-"
                      }}
                    </el-form-item>
                  </el-col>
                </template>
                <template v-if="form.userInfoExpand">
                  <el-col :span="6">
                    <el-form-item label="婚姻状况">
                      {{
                        selectDictLabel(
                          dict.type.marital_status,
                          form.userInfoExpand.marriageStatus
                        ) || "-"
                      }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="家庭地址">
                      {{ form.userInfoExpand.familyAddress || "-" }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="电子邮箱">
                      {{ form.userInfoExpand.email || "-" }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <el-form-item label="月收入">
                      {{ form.userInfoExpand.monthIncome || 0 }} 元
                    </el-form-item>
                  </el-col>
                  <el-col :span="12">
                    <el-form-item label="工作单位">
                      {{ form.userInfoExpand.workplace || "-" }}
                    </el-form-item>
                  </el-col>
                </template>
              </el-row>
            </el-form>
            <el-form label-position="top" v-if="form.emergencyList">
              <div class="item-title-box">紧急联系人</div>
              <div>
                <el-table :data="form.emergencyList">
                  <el-table-column
                    label="与客户关系"
                    align="center"
                    prop="relationship"
                  >
                    <template slot-scope="scope">
                      {{ selectDictLabel(dict.type.relative_type,scope.row.relationship) || '-'}}
                    </template>
                </el-table-column>
                  <el-table-column
                    label="姓名"
                    align="center"
                    prop="emergencyName"
                  ></el-table-column>
                  <el-table-column
                    label="电话"
                    align="center"
                    prop="emergencyPhone"
                  ></el-table-column>
                </el-table>
              </div>
            </el-form>
          </template>
        </el-tab-pane>
        <el-tab-pane label="风控审核" name="2" v-if="form.approveStatus > 0">
          <el-form label-position="top">
            <div class="item-title-box">审核信息</div>
            <el-row :gutter="20" class="form-detail-top-box">
              <el-col :span="6">
                <el-form-item label="审核状态">
                  {{selectDictLabel(dict.type.approve_status,form.approveStatus) || "未知状态"}}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="审核人员">
                  {{ form.approveRealName || '-' }}
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="审核时间">
                  {{ form.approveTime || '-' }}
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="审核备注">
                  {{ form.approveRemark || "-" }}
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
          <el-form label-position="top">
            <div class="item-title-box">补充资料</div>
            <el-row :gutter="20" class="form-detail-top-box">
              <el-col :span="24">
                <imagePreview :url="form.approveUrl" />
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="节点流程" name="7">
          <el-table :data="processList">
            <el-table-column
              label="当前节点"
              align="center"
              prop="handleTitle"
              width="200"
            />
            <el-table-column
              label="处理时间"
              align="center"
              prop="handleTime"
              width="200"
            />
            <el-table-column label="处理状态" align="center" width="250">
              <template slot-scope="scope">
                <el-tag
                  size="small"
                  :type="
                    scope.row.isPass == 1
                      ? 'success'
                      : scope.row.isPass == 2
                      ? 'danger'
                      : ''
                  "
                  >{{ scope.row.handleContent || "-" }}</el-tag
                >
              </template>
            </el-table-column>
            <el-table-column label="操作人" align="center" width="150">
              <template slot-scope="scope">
                {{scope.row.createBy || '-'}}
              </template>
            </el-table-column>

            <el-table-column
              label="处理备注"
              align="center"
              prop="handleRemark"
            />
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </div>
  </el-drawer>
</template>

<script>
import { mapGetters } from 'vuex'
import { getForeseeOrder, getOrderProcess } from "@/api/orderManage/foreseeOrder";
export default {
  name: "OrderDetail",
  dicts: ['approve_status', 'repayment_method',"loan_days",'loan_purpose', 'repayment_term', 'education_level', 'marital_status', 'relative_type'],
  computed: {
    ...mapGetters(['userInfo'])
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    info: {
      type: Object,
      default: ()=>{}
    },
    title: {
      type: String,
      default: '订单详情'
    },
    size: {
      type: [String,Number],
      default: 1000
    },
    isExam: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      show:false,
      form: {},
      processList:[],
      progressStatus:[
        {label: '预审', value:1},
        {label: '录单', value:2},
        {label: '审批', value:3},
        {label: '绑卡', value:4},
        {label: '签约', value:5},
        {label: '合规', value:6},
        {label: '请款', value:7},
      ],
      tabsCurrent: '1',
    };
  },
  watch:{
    visible(){
      this.show = this.visible
      if(this.show){
        this.tabsCurrent = '1'
        this.form = {}
        this.getDetail();
      }
    }
  },
  methods: {
    getDetail() {
      getForeseeOrder({id:this.info.orderId || this.info.id}).then(response => {
        // 联系人
        if(response.data.userInfoExpand){
          if(response.data.userInfoExpand.emergencyNameOne){
            response.data.emergencyList = [{emergencyName: response.data.userInfoExpand.emergencyNameOne,emergencyPhone: response.data.userInfoExpand.emergencyPhoneOne,relationship: response.data.userInfoExpand.relationshipOne}]
          }
          if(response.data.userInfoExpand.emergencyNameTwo){
            response.data.emergencyList.push({emergencyName: response.data.userInfoExpand.emergencyNameTwo,emergencyPhone: response.data.userInfoExpand.emergencyPhoneTwo,relationship: response.data.userInfoExpand.relationshipTwo})
          }
        }
        this.form = response.data;
        getOrderProcess({id:this.form.id}).then(response => {
          this.processList = response.data;
        });
      });
    },
    close(){
      this.$emit('update:visible', false)
      this.$emit('close')
    },
    windowOpen(url){
      window.open(url)
    }
  }
};
</script>